package honeypot.mwzjzt.action;
import java.io.*;

import com.opensymphony.xwork2.ActionSupport;
import com.sun.management.OperatingSystemMXBean;
import sun.management.ManagementFactory;


public class MwzjztAction  extends ActionSupport 
{
	public static String pt="D:\\abc.txt";
	private long free;
	private long use;
	private long total;
	private long physicalFree;
	private long physicalTotal;
	private String os;
	private int totalThread;
	private long physicalUse;
	
	public String execute() throws Exception
	{
		//free和use和total均为KB
		 free=0;
		 use=0;
		 total=0;
		int kb=1024;
		Runtime rt=Runtime.getRuntime();
		total=rt.totalMemory()/kb;
		free=rt.freeMemory()/kb;
		use=total-free;
		System.out.println("系统内存已用的空间为："+use+" MB");
		System.out.println("系统内存的空闲空间为："+free+" MB");
		System.out.println("系统总内存空间为："+total+" MB");
		OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
		 physicalFree=osmxb.getFreePhysicalMemorySize()/kb;
		 physicalTotal=osmxb.getTotalPhysicalMemorySize()/kb;
		 physicalUse=physicalTotal-physicalFree;
		 os=System.getProperty("os.name");
		System.out.println("操作系统的版本："+os);
		System.out.println("系统物理内存的空闲空间为："+physicalFree+" MB");
		System.out.println("系统物理内存已用的空间为："+physicalUse+" MB");
		System.out.println("总物理内存："+physicalTotal+" MB");
        // 获得线程总数
        ThreadGroup parentThread;
        for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
                .getParent() != null; parentThread = parentThread.getParent())
            ;
         totalThread = parentThread.activeCount();
        System.out.println("获得线程总数:"+totalThread);
        return "success";
	}

	public static String getPt() {
		return pt;
	}

	public static void setPt(String pt) {
		MwzjztAction.pt = pt;
	}

	public long getFree() {
		return free;
	}

	public void setFree(long free) {
		this.free = free;
	}

	public long getUse() {
		return use;
	}

	public void setUse(long use) {
		this.use = use;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public long getPhysicalFree() {
		return physicalFree;
	}

	public void setPhysicalFree(long physicalFree) {
		this.physicalFree = physicalFree;
	}

	public long getPhysicalTotal() {
		return physicalTotal;
	}

	public void setPhysicalTotal(long physicalTotal) {
		this.physicalTotal = physicalTotal;
	}

	public String getOs() {
		return os;
	}

	public void setOs(String os) {
		this.os = os;
	}

	public int getTotalThread() {
		return totalThread;
	}

	public void setTotalThread(int totalThread) {
		this.totalThread = totalThread;
	}

	public long getPhysicalUse() {
		return physicalUse;
	}

	public void setPhysicalUse(long physicalUse) {
		this.physicalUse = physicalUse;
	}
	
}


